package JXY01;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

//英雄机
public class Hero extends FlyingObject{
    private int life;
    private int count;
    private BufferedImage[] images;
    private int double_fire = 0;        //双倍子弹剩余数量

    public Hero(){
        image = Aircraft_Battle.hero0;
        life = 3;
        width = image.getWidth();
        height = image.getHeight();
        x = 150;
        y = 500;
        images = new BufferedImage[]{Aircraft_Battle.hero0, Aircraft_Battle.hero1};
        count = 0;
    }
    //发射子弹方法
    public List<Bullet> shoot(){
        List<Bullet> list= new ArrayList<Bullet>();
        //判断有没有双倍子弹剩余火力
        if (double_fire > 0){
            list.add(new Bullet(x - 2 + width/2 - 5,y - 1));
            list.add(new Bullet(x - 2 + width/2 + 5,y - 1));
            double_fire -= 2;
        }else {

        list.add(new Bullet(x - 2 + width/2,y - 1));
        }
        return list;
    }

    //判断撞击
    public boolean crashBy(FlyingObject fly){
        int x = fly.getX();
        int y = fly.getY();
        if (this.x > x - fly.width && this.x < x + fly.width){
            if (this.y > y - fly.height && this.y < y + fly.height){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
    public void move(){
        //切换图片Aircraft_Battle.hero0,Aircraft_Battle.hero1
        count++;
        if(count%5==0){
            setImage(Aircraft_Battle.hero1);
        }else{
            setImage(Aircraft_Battle.hero0);
        }


    }

    public void addLife(){
        life++;
    }
    public void doubleFire(){
        double_fire += 20;
    }
    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
